Ext.define('reportTreeModel', {
    extend: 'Ext.data.Model',
    fields: [
             {name:'text'},
             {name:'q_is_title'},
			 {name:'id'},
// {name:'sql'},
             {name:'table'},
             {name:'unit',type:'int'},
             {name:'q_is_right'},
             {name:'q_is_page'},
             {name:'q_is_sum'},
             {name:'q_is_openrun'},
             {name:'q_is_button'},
             {name:'q_remark'},
			 {name:'leaf'}
			 ]});

Ext.define('fieldTreeModel', {
    extend: 'Ext.data.Model',
    fields: [
             {name:'text'},
             {name:'code'},
			 {name:'id'},
			 {name:'field_type'},
// {name:'field_level'},
			 {name:'data_type'},
			 {name:'data_url'},
			 {name:'data_url_field'},
			 {name:'url_type'},
			 {name:'is_show'},
			 {name:'is_url_param'},
			 {name:'is_sum'},
			 {name:'is_newline'},
// {name:'sort_index'},
			 {name:'field_length'},
			 {name:'data_sort'},
			 {name:'leaf'}
			 ]});

var reportStroe = new Ext.data.TreeStore({
	    model: 'reportTreeModel',
	    proxy: {
	        type: 'ajax',
	        actionMethods:'POST',
	        url: '/sys-report/getReportTree',
	        reader: {
	            type: 'json'
	        }
	    },
	    root:{text:'全部',icon:'/report/image/sysbutton/regionleve1.png'},
	    autoLoad: true
});


var fieldStore = new Ext.data.TreeStore({
    model: 'fieldTreeModel',
    proxy: {
        type: 'ajax',
        actionMethods:'POST',
        url: '/sys-report/getFieldTree',
        reader: {
            type: 'json'
        }
    },
    autoLoad: true
});

var q_id = null;
var q_title = null;
var queryList = {};
var conditionList = {};
var configColumns = new Array();
var currentNode;
var currentReport;
var panelDragTemp = {};
var panelDragFlag = false;
var task1 = true;
var timer1 = true;
var changeFlag = false;
var dropValue = null;
var headerList = null;
var deep = 0;
var columnsNum = 0;
var json_is_title = [
	{id: "0", code: "0", name: "不显示标题"},
	{id: "1", code: "1", name: "显示标题"}
];

var json_unit = [
	{id: "0", code: "0", name: "不显示"},
	{id: "1", code: "1", name: "元"},
	{id: "10000", code: "10000", name: "万元"},
	{id: "100000000", code: "100000000", name: "亿元"}
];
var json_right_type = [
	{id: "0", code: "0", name: "区划权限"},
	{id: "1", code: "1", name: "用户权限"}
];
var json_right = [
	{id: "0", code: "0", name: "不过滤"},
	{id: "1", code: "1", name: "区划过滤"}
];

var json_page = [
	{id: "0", code: "0", name: "不分页"},
	{id: "1", code: "1", name: "分页"}
];

var json_sum = [
	{id: "0", code: "0", name: "合计行不显示"},
    {id: "1", code: "1", name: "合计行显示"}
];

var json_openrun = [
	{id: "0", code: "0", name: "不查询"},
	{id: "1", code: "1", name: "查询"}
];

var json_button = [
	{id: "0", code: "0", name: "不显示"},
	{id: "1", code: "1", name: "显示"}
];

var json_right_level = [
	                    {id: "0", code: "0", name: "单位权限"},
	                    {id: "1", code: "1", name: "财政权限"},
	                    {id: "2", code: "2", name: "财政白名单"}
	                ];

var json_export_level = [
 	                	{id: "0", code: "0", name: "不允许导出"},
 	                	{id: "1", code: "1", name: "导出EXCEL"},
 	                	{id: "2", code: "2", name: "导出全部"}
 	               ];

var json_field_type = [
    {id: "string", code: "string", name: "左对齐字符"},
    {id: "rstring", code: "rstring", name: "右对齐字符"},
    {id: "float", code: "float", name: "浮点数字"},
    {id: "int", code: "int", name: "整数"}
];

var json_url_type = [
    {id: "0", code: "0", name: "新窗口"},
    {id: "1", code: "1", name: "对话框"}
]; 

var json_show_type = [
    {id: "0", code: "0", name: "不可见"},
    {id: "1", code: "1", name: "可见"}
];  

var json_url_param_type = [
    {id: "0", code: "0", name: "非超链接参数"},
    {id: "1", code: "1", name: "超链接参数"}
]; 

var json_sum_type = [
    {id: "0", code: "0", name: "合计行不计算"},
    {id: "1", code: "1", name: "合计行计算"}
];

var json_newline_type = [
    {id: "0", code: "0", name: "不换行"},
    {id: "1", code: "1", name: "自动换行"}
];
   
var json_must_type = [
	{id: "0", code: "0", name: "允许为空"},
	{id: "1", code: "1", name: "不允许为空"}
];

var json_mul = [
	{id: "0", code: "0", name: "单选"},
	{id: "1", code: "1", name: "多选"}
]; 
	  
var json_leaf = [
	{id: "0", code: "0", name: "全部"},
	{id: "1", code: "1", name: "只返回叶子节点"}
];

var json_disp_mode_type = [
	{id: "textfield", code: "textfield", name: "文本框"},
	{id: "combobox", code: "combobox", name: "下拉框"},
	{id: "datefield", code: "datefield", name: "日期"},
	{id: "treecombobox", code: "treecombobox", name: "下拉树"},
	{id: "label", code: "label", name: "描述框"},
	{id: "numberfield", code: "numberfield", name: "数值"}
];

var json_query_relation = [
	{id: "like", code: "like", name: "like"},
	{id: "in", code: "in", name: "in"},
	{id: "=", code: "=", name: "="},
	{id: "<=", code: "<=", name: "<="},
	{id: ">=", code: ">=", name: ">="},
	{id: ">", code: ">", name: ">"},
	{id: "<", code: "<", name: "<"},
	{id: "rlike", code: "rlike", name: "like%"},
	{id: "llike", code: "llike", name: "%like"}
];

var buttons = [{
    xtype: 'button',
    text: '保存报表',
    name: 'save',
    disabled: true,
    icon: '/report/image/sysbutton/save.png',
    handler: function (self) {
    	saveReport();
    }
},{
    xtype: "button", 
    text: '另存为',
    name:'resave',
    icon: '/report/image/sysbutton/resave.png',
    handler: function () {
    	var manageTreePanel = Ext.ComponentQuery.query('treepanel#manageTree')[0];
	   	 var select = manageTreePanel.getSelectionModel().getSelection()[0];
	   	 if(select && select.get("leaf")){
             initWindow_report_resave(select);
	   	 }else{
	   		 Ext.MessageBox.alert('提示', '请选择查询报表');
	   	 }
    }
},{
    xtype: 'button',
    text: '新增目录',
    icon: '/report/image/sysbutton/add.png',
    handler: function (self) {
    	 var manageTreePanel = Ext.ComponentQuery.query('treepanel#manageTree')[0];
	   	 var select = manageTreePanel.getSelectionModel().getSelection()[0];
	   	 var parent_id = "";
	   	 var levelno = 1;
	   	 var parent_name = "全部";
	   	 if(select){
	   		if(select.get("leaf")){
	   			Ext.MessageBox.alert('提示', '请选择目录');
        		return;
        	 }
	   		
	   		if(select.get("id")!="root"){
	   			levelno = select.get("depth")+1;
		   		parent_id = select.get('id');
		   		parent_name = select.get('text');
	   		}
	   		initWindow_file_add(parent_id,levelno,parent_name);
	   	 }else{
	   		Ext.MessageBox.alert('提示', '请选择目录');
	   	 }
    }
},{
    xtype: 'button',
    text: '新增',
    icon: '/report/image/sysbutton/add.png',
    handler: function (self) {
    	 var manageTreePanel = Ext.ComponentQuery.query('treepanel#manageTree')[0];
	   	 var select = manageTreePanel.getSelectionModel().getSelection()[0];
	   	 var parent_id = "";
	   	 if(select){
	   		if(!select.get("leaf") && select.get("id") !='root'){
	   			parent_id = select.get('id');
        	 }
	   	 }
    	initWindow_report_config({
    		xiugai:'xiugai',
    		parent_id:parent_id
		 });
    }
},{
    xtype: 'button',
    text: '修改',
    icon: '/report/image/sysbutton/edit.png',
    handler: function (self) {
    	 var manageTreePanel = Ext.ComponentQuery.query('treepanel#manageTree')[0];
	   	 var select = manageTreePanel.getSelectionModel().getSelection()[0];
	   	 if(select && select.get("leaf")){
	   		 var id = select.get('id');
	   		 var q_is_title = select.get('q_is_title');
        	 var text = select.get('text');
        	 var table = select.get('table');
        	 var unit = select.get('unit');
        	 var q_is_right = select.get('q_is_right');
        	 var q_is_page = select.get('q_is_page');
        	 var q_is_sum = select.get('q_is_sum');
        	 var q_is_openrun = select.get('q_is_openrun');
        	 var q_is_button = select.get('q_is_button');
        	 var q_remark = select.get('q_remark');
        	 var right_level = select.get('right_level');
        	 var export_level = select.get('export_level');
	   		 var data = {
	   				Q_ID: id,
	   				Q_IS_TITLE: q_is_title,
	   				Q_TITLE: text,
            		Q_TABLE: table,
            		MONEY_UNIT: unit,
            		Q_IS_RIGHT: q_is_right,
            		Q_IS_PAGE: q_is_page,
            		Q_IS_SUM: q_is_sum,
            		Q_IS_OPENRUN: q_is_openrun,
            		Q_REMARK:q_remark,
            		Q_IS_BUTTON: q_is_button,
            		RIGHT_LEVEL:right_level,
            		EXPORT_LEVEL:export_level
                 };
	    	initWindow_report_config({
	    		xiugai:'xiugai',
	    		edit:true,
	    		data:data
	    	});
	   	 }else{
	   		 Ext.MessageBox.alert('提示', '请先选查询报表再进行修改');
	   	 }
    }
},{
    xtype: 'button',
    text: '删除',
    name: 'delete',
    icon: '/report/image/sysbutton/delete.png',
    handler: function (btn) {
    	var manageTreePanel = Ext.ComponentQuery.query('treepanel#manageTree')[0];
   	 	var select = manageTreePanel.getSelectionModel().getSelection()[0];
   	 	if(select){
   	 		var id = select.get("id");
   	 		var text = select.get("text");
   	 		Ext.Msg.confirm('提示', '请确认是否删除'+text, function (btn_confirm) {
   	 			if (btn_confirm == 'yes') {
                	 // 发送ajax请求，删除数据
   	 				$.post("/sys-report/deleteQueryReport", {
                    	Q_ID: id
                    }, function (data) {
                        if (data.success) {
                            Ext.toast({
                                html: "删除成功！",
                                closable: false,
                                align: 't',
                                slideInDuration: 400,
                                minWidth: 400
                            });
                            changeFlag = false;
                            manageTreePanel.getStore().load();
                            Ext.ComponentQuery.query('button[name="save"]')[0].setDisabled(true);
                            var fieldTree = Ext.ComponentQuery.query('treepanel#fieldTree')[0];
                            var fieldStore = fieldTree.getStore();
                            fieldStore.getProxy().extraParams = {
                            	table:""
                            };
                            fieldStore.load();
                            var mainPanel = Ext.ComponentQuery.query('panel#mainPanel')[0];
                    		mainPanel.removeAll(true);
                    		var rightConfig = Ext.ComponentQuery.query('panel#rightConfig')[0];
        	        		rightConfig.removeAll(true);
                        } else {
                            Ext.MessageBox.alert('提示', '删除失败！' + data.message);
                        }
                    }, "json");
   	 			}
   	 		}); 
   	 	}else{
   	 		Ext.MessageBox.alert('提示', '请先选查询报表再进行删除');
   	 	}
    }
},{
    xtype: 'button',
    text: '预览',
    icon: '/report/image/sysbutton/search.png',
    handler: function (self) {
    	 var manageTreePanel = Ext.ComponentQuery.query('treepanel#manageTree')[0];
	   	 var select = manageTreePanel.getSelectionModel().getSelection()[0];
	   	 if(select && select.get("leaf")){
        	 var q_id =  select.get('id');
             var Q_NAME = select.get('text');
             var yl_url = "/report/page/plat/query/reportQuery.jsp?code="+q_id+"&adcode="+adcode;
         	 window.open(yl_url, '_blank');
	   	 }else{
	   		 Ext.MessageBox.alert('提示', '请先选查询报表再进行预览');
	   	 }
    }
},{
    xtype: 'button',
    text: '导入',
    icon: '/report/image/sysbutton/import.png',
    handler: function (self) {
    	var AddfileForm=new Ext.FormPanel({
    		name : 'AddfileForm',
		    frame : true,
		    url : '/sys-report/ext-form/impQueryReport',
		    fileUpload : true,
		    width : 400,
		    autoDestroy : true,
		    items : [{
				xtype : 'filefield',
		        emptyText : '选择上传报表文件',
		        fieldLabel : '文件',
		        name : 'upload',
				labelWidth : 40,
		        anchor : '95%',
				margin:'15 0 0 15',
				buttonText:'浏览',
		        buttonConfig: {
					width: 70,
				    icon: '/report/image/sysbutton/report.png'
				},
		        validator: function(value){
					var temp = value.split('.');
					var tmep1 = temp[temp.length-1];
	                var temp2 = tmep1.toLowerCase();
					var allowType = 'xml';
	                if (allowType.indexOf(temp2) == -1) {
	                	return "不允许选择该类型文件，请选择xml文件！";
	                } else {
						return true;
					}
				}
			}]
    	});
		var AddfileWin=new Ext.Window({
	        title: '导入报表',
	        width: 500,
	        height: 150,
	        layout: 'fit',
	        plain: true,
	        buttonAlign: 'center',
	        items: AddfileForm,
	        buttons: ['->',{
	            text: '导入',
	            handler: function (btn) {
	            	if (AddfileForm.getForm().isValid()) {
	            		Ext.MessageBox.show({
   	            			title : '请稍等...',
   	            		    msg : '文件上传中...',
   	            		    progressText : '',
   	            		    width : 300,
   	            		    progress : true,
   	            		    closable : false,
   	            		    animEl : 'loding'
   	            		 });
	            		 AddfileForm.getForm().submit({
	            			success: function (form, action) {
	            				Ext.MessageBox.close();
	                        	AddfileWin.close();
	                        	var manageTreePanel = Ext.ComponentQuery.query('treepanel#manageTree')[0];
                                manageTreePanel.getStore().load();
                                Ext.ComponentQuery.query('button[name="save"]')[0].setDisabled(true);
                                var mainPanel = Ext.ComponentQuery.query('panel#mainPanel')[0];
                          		mainPanel.removeAll(true);
                          		var rightConfig = Ext.ComponentQuery.query('panel#rightConfig')[0];
              	        		rightConfig.removeAll(true);
              	        		initWindow_report_import(action.result.qidList);
	                        },
	                        failure: function (form, action) {
	                            var msg = action.result.message;
	                            Ext.MessageBox.show({
	                                title: '提示',
	                                msg: '导入失败:'+msg,
	                                width: 200,
	                                fn: function (btn) {
	                                }
	                            });
	                        }
	                    });
	            	}
	            }
	        },{
	        	text: '关闭',
	            handler: function () {
	            	AddfileWin.close();
	            }
	        }]
	    });
		AddfileWin.show();
    }
},{
    xtype: 'button',
    text: '导出',
    icon: '/report/image/sysbutton/export.png',
    handler: function (self) {
    	initWindow_report_export();
    }
},{
	xtype:'button',
	text:'打印配置',
	icon: '/report/image/sysbutton/print.png',
	handler:function(){
		var manageTreePanel = Ext.ComponentQuery.query('treepanel#manageTree')[0];
	   	var select = manageTreePanel.getSelectionModel().getSelection()[0];
	   	if(select && select.get("leaf")){
	   		var id = select.get('id');
        	var text = select.get('text');
            $.post("/sys-report/getReportPrintConfig", {
            	Q_ID: id
            }, function (data) {
            	var printConfig = data.print_config;
	            var headerLeft = "";
	            var headerCenter = "";
	            var headerRight = "";
	            var footerLeft = "";
	            var footerCenter = "";
	            var footerRight = "";
	            if(printConfig){
	            	var tempPrint = printConfig.split('#');
	                if(tempPrint.length >= 2){
	                	var printFooter = tempPrint[1];
	                	var tempPrintFooter = printFooter.split('-');
	                	footerLeft = tempPrintFooter[0];
		                if(tempPrintFooter.length >=2){
		                	footerCenter = tempPrintFooter[1];
		                }
		                if(tempPrintFooter.length >=3){
		                	footerRight = tempPrintFooter[2];
		                }
	                }
	                var printHeader = tempPrint[0];
	                var tempPrintHeader = printHeader.split('-');
	                headerLeft = tempPrintHeader[0];
	                if(tempPrintHeader.length >=2){
	                	headerCenter = tempPrintHeader[1];
	                }
	                if(tempPrintHeader.length >=3){
	                	headerRight = tempPrintHeader[2];
	                }
	            }
	            var data = {
	            		Q_ID: id,
				   		HEADER_LEFT: headerLeft,
				   		HEADER_CENTER: headerCenter,
				   		HEADER_RIGHT: headerRight,
				   		FOOTER_LEFT: footerLeft,
				   		FOOTER_CENTER: footerCenter,
				   		FOOTER_RIGHT: footerRight
	            };
				initWindow_report_print_config({
					title:text,
				    data:data
				});
            }, "json");
	   	}else{
	   		Ext.MessageBox.alert('提示', '请先选查询报表再进行配置');
	   	}
	}
}];

/**
 * 切换报表
 * 
 * @param record
 */
function changeReport(record){
	changeFlag = false;
	queryList = {};
	conditionList = {};
	configColumns = new Array();
	q_id = record.get("id");
	var table = record.get("table");
	if(table == null){
		Ext.MessageBox.minWidth = 120;
		Ext.Msg.alert('提示', '请配置数据源！');
		return;
	}
	var fieldTree = Ext.ComponentQuery.query('treepanel#fieldTree')[0];
    var fieldStore = fieldTree.getStore();
    fieldStore.getProxy().extraParams = {
    	q_id:q_id
    };
    fieldStore.load();
    var mainPanel = Ext.ComponentQuery.query('panel#mainPanel')[0];
	mainPanel.removeAll(true);
	loadReport(q_id);
	mainPanel.add(initSelect());
 	mainPanel.add(initGrid());
	$("#reportManageGridIframe").attr("src", "/report/page/plat/query/manage/zcell/zCell.jsp");
	conditionConf(conditionList);
	Ext.ComponentQuery.query('button[name="save"]')[0].setDisabled(false);
	var rightConfig = Ext.ComponentQuery.query('panel#rightConfig')[0];
	rightConfig.removeAll(true);
	var id = record.get('id');
	var text = record.get('text');
	var q_is_title = record.get('q_is_title');
	var unit = record.get('unit');
	var q_is_right = record.get('q_is_right');
	var q_is_page = record.get('q_is_page');
	var q_is_sum = record.get('q_is_sum');
	var q_is_openrun = record.get('q_is_openrun');
	var q_is_button = record.get('q_is_button');
	var q_remark = record.get('q_remark');
	var right_level = record.get('right_level');
	var export_level = record.get('export_level');
	var data = {
			Q_ID: id,
			Q_TITLE: text,
			Q_IS_TITLE: q_is_title,
			Q_TABLE: table,
			MONEY_UNIT: unit,
			Q_IS_RIGHT: q_is_right,
			Q_IS_PAGE: q_is_page,
			Q_IS_SUM: q_is_sum,
			Q_IS_OPENRUN: q_is_openrun,
			Q_REMARK:q_remark,
			Q_IS_BUTTON: q_is_button,
			RIGHT_LEVEL:right_level,
			EXPORT_LEVEL:export_level
		};
	rightConfig.setTitle("基本信息配置");
	rightConfig.add(initWindow_report_config_contentForm({
		edit:true,
		columnWidth:.99,
	    data: data,
	    saveFlag:true
    }));
}

/**
 * 加载报表配置信息
 * 
 * @param code
 */
function loadReport(code){
    Ext.Ajax.request({
		method : 'POST',
		url : "/sys-report/getReportQueryConfigData",
		params : { 
			code:code
		},
		async : false,
		success : function(response, options) {
			// 获取返回的JSON，并根据gridid，获取表头配置信息
			var respText = Ext.util.JSON.decode(response.responseText);
			q_id = respText.qId;
			q_title = respText.qTitle;
			conditionList =  eval(respText.conditionList);
			configColumns = eval(respText.fieldList);
			headerList = eval(respText.headerList);
			deep = respText.deep;
			columnsNum = respText.columnsNum;
		},
		failure : function(response, options) {
			Ext.MessageBox.minWidth = 120;
			Ext.Msg.alert('提示', '获取报表配置信息失败！');
		}
    });
}


/**
 * sql预览添加参数
 * 
 * @param parameter
 * @returns
 */
function initWindow_table_condition_info(parameter){
	var conditionItems = [];
	for(var i = 0;i<parameter.length;i++){
		conditionItems.push({
			fieldLabel:parameter[i],
			name:parameter[i]
		});
	}
	var form = Ext.create('Ext.form.Panel', {
        width: '100%',
        height: '100%',
        itemId: 'initWindow_table_condition_info',
        layout: 'column',
        scrollable:true,
        defaultType: 'textfield',
        defaults: {
            margin: '4 10 0 4',
            columnWidth:.99,
            labelAlign:'right',
            labelWidth: 90// 控件默认标签宽度
        },
        items: conditionItems
    });
    return form;
}


/**
 * SQL预览结果界面
 * 
 * @param table
 * @param header
 * @param title
 * @param formData
 * @returns
 */
function initWindow_table_info(table,header,title,formData){
	var dataGrid = DSYGrid.createGrid({
        itemId: 'tableInfo',
        headerConfig: {
        	headerJson:header,
            columnAutoWidth: false
        },
        checkBox: false,
        border: false,
        autoLoad: false,
        width:'100%',
        flex: 8,
        dataUrl: '/report/page/plat/sys/getTableData.action',
        params:{
     	   runsql:table,
     	   detailForm: Ext.util.JSON.encode([formData])
        },
        pageConfig: {
            enablePage: true,
            pageSize : 20,
   			inputItemWidth:52,
   			pageNum : true
        },
        isLocalStorage: false
	});
	  var panel = Ext.create('Ext.panel.Panel', {
	        width: '100%',
	        height: '100%',
	        scrollable:true,
	        border:false,
	        layout: 'fit',
	        items: [dataGrid]
	    });
	  var startD = new Date();
	  var grid = DSYGrid.getGrid('tableInfo');
	  var store = grid.getStore();
	  store.load({
		  callback: function(records, operation, success) {
			  var endD = new Date();
	    	  var useD = (endD.getTime()-startD.getTime())/1000;
	    	  useD = numberFormat(useD,2,1);
	    	  var tablePanle = Ext.ComponentQuery.query('window#window_table_info')[0];
	    	  tablePanle.setTitle(title+"（查询耗时："+useD+"秒）")
		  }
	  });
	  return panel;
}


/**
 * 树检索
 * 
 * @param self
 *            搜索按钮/检索框
 */
function treeSearch(value) {
    var tree = Ext.ComponentQuery.query('treepanel#manageTree')[0];
    var treeStroe = tree.getStore();
    var btn_search = tree.down('textfield[name="search_text"]');
    var roonodes = tree.getRootNode();// 获取主节点
    var textValue = btn_search.getValue();
    if(value){
    	textValue = value;
    }
    if(textValue == null || textValue == 'undefined' || textValue.length == 0){
    	tree.getView().scrollTo(0, 0, true);
    	tree.getSelectionModel().clearSelections();
        return true;
    }
    // 如果搜索框内容与上次搜索内容不一致，更新
    if (!btn_search.search_value || btn_search.search_value.toLowerCase() != textValue.toLowerCase()) {
    	tree.getSelectionModel().clearSelections();
        btn_search.search_start = 0;
        btn_search.search_value = textValue;
        if (typeof(btn_search.search_result)=="undefined") {
        	btn_search.search_result = new Array();
        	btn_search.search_resultCount = 0;
    	}
    }else{
    	if(typeof(tree.getSelectionModel().getSelection()[0])!="undefined"){
    		btn_search.search_result[btn_search.search_resultCount] = tree.getSelectionModel().getSelection()[0].data.name;
    		btn_search.search_resultCount = btn_search.search_resultCount+1;
        }
    }
    expandLeafByFinddata(roonodes,tree,textValue,btn_search.search_result,"treePanel",true,true);  // 开始递归
    // 循环store，检索搜索内容是否存在,
    var start_index = btn_search.search_start;
    var find = false;
    while (true) {
        btn_search.search_start++;
        if (btn_search.search_start >= treeStroe.getCount()) {
            btn_search.search_start = 0;
        }
        var record = treeStroe.getAt(btn_search.search_start);
        var value = record.get('text') + record.get('id');
        if (value.toLowerCase().indexOf(textValue.toLowerCase()) >= 0) {
        	tree.expandPath(record.getPath('id'));
            var scorll_height = btn_search.search_start * (tree.getView().getNodes()[0].clientHeight) > 100 ? btn_search.search_start * (tree.getView().getNodes()[0].clientHeight) - 100 : 0;
            tree.getSelectionModel().select(record);
            tree.getView().scrollTo(0, scorll_height, true);
            find = true;
            break;
        }
        if (start_index == btn_search.search_start) {
            break;
        }
    }
    if (!find) {
        Ext.toast({
            html: '无此数据',
            closable: false,
            align: 't',
            slideInDuration: 400,
            minWidth: 400
        });
    }
}



/**
 * 保存报表
 * 
 * @returns
 */
function saveReport(){
	Ext.ComponentQuery.query('button[name="save"]')[0].setDisabled(true);
	if(!mapIsEmpty(queryList)){
		var qId = queryList.Q_ID;
		var qTitle = queryList.Q_TITLE;
		var qTable = queryList.Q_TABLE;
		if(qId == null || qId ==""){
			 Ext.ComponentQuery.query('button[name="save"]')[0].setDisabled(false);
			 Ext.MessageBox.alert('提示', '请填写报表ID!');
			 return;
		}
		if(qTitle == null || qTitle ==""){
			 Ext.ComponentQuery.query('button[name="save"]')[0].setDisabled(false);
			 Ext.MessageBox.alert('提示', '请填写报表名称!');
			 return;
		}
		if(qTable == null || qTable ==""){
			 Ext.ComponentQuery.query('button[name="save"]')[0].setDisabled(false);
			 Ext.MessageBox.alert('提示', '请填写表/视图或数据源sql!');
			 return;
		}
	}
	var conditionErrorFlag = false;
	var errorMessage = "";
	for(var i = 0; i < conditionList.length; i++){
		var condition = conditionList[i];
		var cCode = condition.C_CODE;
		var cTitle = condition.C_TITLE;
		var cFieldCode = condition.C_FIELD_CODE;
		var cDispMode = condition.C_DISP_MODE;
		var cDataModel = condition.C_DATA_MODEL;
		var cDataSource = condition.C_DATA_SOURCE;
		var queryRelation = condition.QUERY_RELATION;
		if(cCode == null || cCode ==""){
			 errorMessage = "请填写控件编码!";
			 conditionErrorFlag = true;
			 break;
		}
		if(cTitle == null || cTitle ==""){
			 Ext.ComponentQuery.query('button[name="save"]')[0].setDisabled(false);
			 errorMessage = "请填写控件名称!";
			 conditionErrorFlag = true;
			 break;
		}
		if(cDispMode == "treecombobox" || cDispMode == "combobox"){
			if((cDataModel == null || cDataModel =="")&&(cDataSource == null || cDataSource =="")){
				errorMessage = "下拉框、下拉树需配置数据集!";
				conditionErrorFlag = true;
				break;
			}
		}
	}
	if(conditionErrorFlag){
		Ext.ComponentQuery.query('button[name="save"]')[0].setDisabled(false);
		Ext.MessageBox.alert('提示', errorMessage);
		return;
	}
	var cells = document.getElementById("reportManageGridIframe").contentWindow.getCells();
	var cellProperty = document.getElementById("reportManageGridIframe").contentWindow.getCellProperty();
	var columnData = [];
	var keyList = [];
	var cellRow = cells[0];
	for ( var i = 0; i < cellRow.length; i++) {
		var cell = cellRow[i];
		var value = cell.Value;
		if(!value){
			break;
		}
		// value id parent isLeaf width
		var colSpan = cell.colSpan;
		var rowNo = cell.rowNo;
		var colNo = cell.colNo;
		var key = rowNo + "#" + colNo;
		keyList.push(key);
		var cellId = cellProperty[key];
		if(!cellId){
			cellId = GUID.createGUID();
			cellProperty[key] = cellId;
		}
		var cellMap = {
			id :cellId,
			value :value,
			width : cell.clientWidth
		};
		if(colSpan > 1){
			cellMap["isLeaf"] = "0";
			i = colNo+colSpan - 2;
			columnData.push(cellMap);
			getChildColumn(cellId,rowNo,colNo,colSpan);
		}else{
			cellMap["isLeaf"] = "1";
			columnData.push(cellMap);
		}
	}
	
	function getChildColumn(cellId,rowNo,colNo,colSpan){ 
		  var childCellRow = cells[rowNo];
		  for ( var i = colNo-1; i < colNo+colSpan-1; i++) {
			  var childCell = childCellRow[i];
			  var childValue = childCell.Value;
				// value id parent isLeaf width
			  var childColSpan = childCell.colSpan;
			  var childRowNo = childCell.rowNo;
			  var childColNo = childCell.colNo;
			  var childKey = childRowNo + "#" + childColNo;
			  keyList.push(childKey);
			  var childcellId = cellProperty[childKey];
			  if(!childcellId){
				  childcellId = GUID.createGUID();
				  cellProperty[key] = childcellId;
			  }
			 var childCellMap = {
					 id :childcellId,
					 value :childValue,
					 width : childCell.clientWidth,
					 parent :cellId
			 };
			 if(childColSpan > 1){
				   childCellMap["isLeaf"] = "0";
					i = childColNo+childColSpan - 2;
					columnData.push(childCellMap);
					getChildColumn(childcellId,childRowNo,childColNo,childColSpan);
				}else{
					childCellMap["isLeaf"] = "1";
					columnData.push(childCellMap);
				}
		 }
	}
	
	/*
	 * for(var i = 0; i< keyList.length; i++){ var key = keyList[i];
	 * if(!cellProperty[key]){ var row = parseInt(key.split("#")[0]); var col =
	 * parseInt(key.split("#")[1]); var cellId = GUID.createGUID();
	 * cellProperty[key] = cellId;
	 * document.getElementById("reportManageGridIframe").contentWindow.setCellProperty(row,col,cellId); } }
	 */
	 
	for(var key in cellProperty){
		var keyFlag = false;
		for(var i = 0; i< keyList.length; i++){
			if(key == keyList[i]){
				keyFlag = true;
				break;
			}
		}
		if(!keyFlag){
			delete cellProperty[key]; 
		}
	}
	
	for(var key in cellProperty){
		var cellFlag = false;
		var cellId = cellProperty[key];
		for(var i = 0; i< configColumns.length; i++){
			if(configColumns[i].F_ID == cellId){
				if(!configColumns[i].FIELD_TITLE){
					var row = parseInt(key.split("#")[0]);
					var col = parseInt(key.split("#")[1]);
					var cellValue = document.getElementById("reportManageGridIframe").contentWindow.getCellValue(row,col);
					configColumns[i].FIELD_TITLE = cellValue;
				}
				cellFlag = true;
				break;
			}
		}
		if(!cellFlag){
			var row = parseInt(key.split("#")[0]);
			var col = parseInt(key.split("#")[1]);
			var cellValue = document.getElementById("reportManageGridIframe").contentWindow.getCellValue(row,col);
			configColumns.push({
				F_ID:cellId,
				FIELD_TITLE:cellValue
			});
		}
	}
	for(var i = 0; i< configColumns.length; i++){
		var columnFlag = false;
		for(var key in cellProperty){
			if(configColumns[i].F_ID == cellProperty[key]){
				columnFlag = true;
				break;
			}
		}
		if(!columnFlag){
			configColumns.splice(i, 1);
			i--;
		}
	}
	if(configColumns && configColumns.length > 0){
		for(var i = 0; i< configColumns.length; i++){
			var field = configColumns[i];
			var fieldCode = field.FIELD_CODE;
			var fieldTitle = field.FIELD_TITLE;
			if(fieldTitle == null || fieldTitle ==""){
				 Ext.ComponentQuery.query('button[name="save"]')[0].setDisabled(false);
				 Ext.MessageBox.alert('提示', '请填写数据列名称!');
				 return;
			}
			var sameFlag = false;
			if(fieldCode){
				for(var j = 0; j< configColumns.length; j++){
					if(field.F_ID != configColumns[j].F_ID ){
						var fieldCode1 = configColumns[j].FIELD_CODE;
						if(fieldCode == fieldCode1){
							sameFlag = true;
							break;
						}
					}
				}			
			}
			if(sameFlag){
				Ext.ComponentQuery.query('button[name="save"]')[0].setDisabled(false);
				 Ext.MessageBox.alert('提示', '数据列编码：'+fieldCode+'重复！');
				 return;
			}
		}
	}
	
	$.post("/sys-report/saveReportInfoZcell", {
		configColumns:Ext.util.JSON.encode(configColumns),
		conditionList:Ext.util.JSON.encode(conditionList),
		queryList:Ext.util.JSON.encode(queryList),
		columnData:Ext.util.JSON.encode(columnData),
		q_id:q_id
	}, function(data) {
    	if (data.success) {
            Ext.toast({
                html: "保存成功！",
                closable: false,
                align: 't',
                slideInDuration: 400,
                minWidth: 400
            });
            changeFlag = false;
            var manageTreePanel = Ext.ComponentQuery.query('treepanel#manageTree')[0];
            manageTreePanel.getStore().load({
    		    callback: function(records, operation, success) {
    		    	var node = manageTreePanel.getStore().getNodeById(q_id);
    		    	treeSearch(q_id);
    		    	queryList = {};
    		    	var table = node.get("table");
    		    	if(table == null){
    		    		Ext.MessageBox.minWidth = 120;
    		    		Ext.Msg.alert('提示', '请配置数据源！');
    		    		return;
    		    	}
    		    	var fieldTree = Ext.ComponentQuery.query('treepanel#fieldTree')[0];
    		        var fieldStore = fieldTree.getStore();
    		        fieldStore.getProxy().extraParams = {
    		        	q_id:q_id
    		        };
    		        fieldStore.load();
// changeReport(node);
    		    }
            });
    	}else {
                Ext.MessageBox.alert('提示', '保存失败！' + data.message);
            }
    	Ext.ComponentQuery.query('button[name="save"]')[0].setDisabled(false);
    }, "json");
}

/**
 * 报表另存为
 * 
 * @param select
 * @returns
 */
function initWindow_report_resave(select){
    // 弹出弹出框
	Ext.create('Ext.window.Window', {
		title: '另存为报表', // 窗口标题
        width: document.body.clientWidth * 0.45,// 窗口宽度
        height: document.body.clientHeight * 0.8, // 窗口高度
        layout: 'fit',
        maximizable: true,
        buttonAlign: 'right', // 按钮显示的位置
        modal: true, // 模式窗口，弹出窗口后屏蔽掉其他组件
        closeAction: 'destroy',// hide:单击关闭图标后隐藏，可以调用show()显示。如果是destroy，则会将window销毁。
        items: initWindow_report_resave_contentForm(),
        buttons: [{
        	xtype:'textfield',
	       	fieldLabel: '<span class="required">✶</span>报表名称',
	    	name: 'FILE_ID',
	    	labelAlign: "left",
		    labelWidth: 68,
		    width:'35%',
	    	allowBlank: false// 允许为空
        },{
        	xtype:'textfield',
	       	fieldLabel: '<span class="required">✶</span>报表标题',
	    	name: 'FILE_NAME',
	    	labelAlign: "left",
		    labelWidth: 68,
		    width:'35%',
		    value:select.get('text'),
	    	allowBlank: false// 允许为空
		},{
			xtype: 'button',
	        text: '保存',
	        handler: function (self) {
	        	var fileName = Ext.ComponentQuery.query('textfield[name="FILE_NAME"]')[0].getValue();
	            var fileId = Ext.ComponentQuery.query('textfield[name="FILE_ID"]')[0].getValue();
	            var resaveReportPanel = Ext.ComponentQuery.query('treepanel#resaveReportTree')[0];
	            var result = resaveReportPanel.getSelectionModel().getSelection()[0];
	            if(!fileId){
	            	Ext.MessageBox.alert('提示', '报表名称不允许为空!');
	            	return;
	            }
	            if(!fileName){
	            	Ext.MessageBox.alert('提示', '报表标题不允许为空!');
	            	return;
	            }
	            var parentId = "";
            	var copy_id = select.get("id");
	            if(result){
	            	if(!result.get("leaf")){
	            		parentId = result.get("id");
	            	}else{
	            		Ext.MessageBox.alert('提示', '请选择文件目录!');
	            		return;
	            	}
	            }
	            $.post('/sys-report/resaveReport', {
            		parentId:parentId,
            		copy_id:copy_id,
            		fileId:fileId,
            		fileName:fileName
				}, function(data) {
                	if (data.success) {
                    	Ext.toast({
                        	html: "保存成功！",
                            closable: false,
                            align: 't',
                            slideInDuration: 400,
                            minWidth: 400
                        });
                    	self.up('window').close();
                        q_id = data.qid;
                    	var manageTreePanel = Ext.ComponentQuery.query('treepanel#manageTree')[0];
                        manageTreePanel.getStore().load({
                        	callback: function(records, operation, success) {
                            	var node = manageTreePanel.getStore().getNodeById(q_id);
                            	currentReport = node;
                            	manageTreePanel.getSelectionModel().select(node);
                            	treeSearch(q_id);
                            	changeReport(node);
                            }
                        });
                	} else {
                		Ext.MessageBox.alert('提示', '保存失败!' + data.message);
                    }
                }, 'JSON');
	        }
		},{
	    	xtype: 'button',
	        text: '关闭',
	        handler: function (self) {
	        	self.up('window').close();
	        }
	   }]
   }).show();
}

/**
 * 报表另存为
 * 
 * @returns
 */
function initWindow_report_resave_contentForm() {
	var resaveReportStroe = new Ext.data.TreeStore({
	    model: 'reportTreeModel',
	    proxy: {
	        type: 'ajax',
	        actionMethods:'POST',
	        url: '/sys-report/getReportTree',
	        reader: {
	            type: 'json'
	        }
	    },
	    autoLoad: true
	});
    var form = Ext.create('Ext.panel.Panel', {
    	width: '100%',
        height: '100%',
        scrollable:true,
        border:false,
        layout: 'fit',
        items: [{
        	xtype:'treepanel',
            itemId: 'resaveReportTree',
            store: resaveReportStroe,
            rootVisible: false
        }]
    });
    return form;
}

/**
 * 新增目录
 * 
 * @param parent_id
 * @param levelno
 * @param parent_name
 * @returns
 */
function initWindow_file_add(parent_id,levelno,parent_name){
    // 弹出弹出框
   Ext.create('Ext.window.Window', {
       title: '新增目录', // 窗口标题
       width: 400, // 窗口宽度
       height: 170, // 窗口高度
       layout: 'fit',
       maximizable: true,
       buttonAlign: 'right', // 按钮显示的位置
       modal: true, // 模式窗口，弹出窗口后屏蔽掉其他组件
       closeAction: 'destroy',// hide:单击关闭图标后隐藏，可以调用show()显示。如果是destroy，则会将window销毁。
       items: [{
    	   xtype: 'form',
	       width: '100%',
	       height: '100%',
	       layout: 'column',
	       autoScroll: true,
	       defaultType: 'textfield',
	       defaults: {
	       		margin: '10 5 5 5',
	            columnWidth: .99,
	            labelAlign: "right",
	            labelWidth: 100// 控件默认标签宽度
	       },
	       items: [{
	    	   fieldLabel: '<span class="required">✶</span>父目录',
	    	   name: 'PARENT_NAME',
	    	   allowBlank: false,// 允许为空
	    	   disabled:true,
	    	   value:parent_name
	       },{
	    	   fieldLabel: '<span class="required">✶</span>目录名称',
	    	   name: 'FILE_NAME',
	    	   allowBlank: false// 允许为空
	       }]
       }],
       buttons: [{
    	   xtype: 'button',
           text: '保存',
           handler: function (self) {
        	   var form = self.up('window').down('form');
               if (form.isValid()) {
            	   var formData = form.getForm().getFieldValues();
                   formData = $.extend({}, formData, form.getValues());
                   formData.parent_id = parent_id;
                   formData.levelno = levelno;
                   $.post('/sys-report/addReportFile', {
                	   detailForm: Ext.util.JSON.encode([formData])
                   }, function (data) {
                	   if (data.success) {
                		   Ext.toast({
                			   html: "保存成功！",
                               closable: false,
                               align: 't',
                               slideInDuration: 400,
                               minWidth: 400
                		   });
                           self.up('window').close();
                           var manageTreePanel = Ext.ComponentQuery.query('treepanel#manageTree')[0];
                           manageTreePanel.getStore().load();
                	   } else {
                		   Ext.MessageBox.alert('提示', '保存失败!' + data.message);
                       }
                   }, 'JSON');
               }
           }
       },{
    	   xtype: 'button',
           text: '取消',
           handler: function (self) {
           		self.up('window').close();
           }
      }]
   }).show();
}

/**
 * 导入报表
 * 
 * @param qidList
 * @returns
 */
function initWindow_report_import(qidList){
    // 弹出弹出框
   Ext.create('Ext.window.Window', {
       title: '导入报表', // 窗口标题
       width: document.body.clientWidth * 0.4, // 窗口宽度
       height: document.body.clientHeight * 0.8, // 窗口高度
       layout: 'fit',
       maximizable: true,
       buttonAlign: 'right', // 按钮显示的位置
       modal: true, // 模式窗口，弹出窗口后屏蔽掉其他组件
       closeAction: 'destroy',// hide:单击关闭图标后隐藏，可以调用show()显示。如果是destroy，则会将window销毁。
       items: initWindow_report_import_content(qidList),
       buttons: [{
    	   xtype: 'button',
    	   text: '关闭',
    	   handler: function (self) {
    		   self.up('window').close();
    	   }
       }]
   }).show();
}	  

/**
 * 导入报表
 * 
 * @param qidList
 * @returns
 */
function initWindow_report_import_content(qidList){
	var importReportStroe = new Ext.data.TreeStore({
	    model: 'reportTreeModel',
	    proxy: {
	        type: 'ajax',
	        actionMethods:'POST',
	        url: '/sys-report/getImportReportTree',
	        extraParams: {
	        	qidList:Ext.util.JSON.encode(qidList),
	        },
	        reader: {
	            type: 'json'
	        }
	    },
	    autoLoad: true
	});
    var form = Ext.create('Ext.panel.Panel', {
    	width: '100%',
        height: '100%',
        scrollable:true,
        border:false,
        layout: 'fit',
        items: [{
        	xtype:'treepanel',
        	itemId: 'importReportTree',
        	store: importReportStroe,
        	rootVisible: false
        }]
    });
    return form;
}


/**
 * 报表导出
 * 
 * @returns
 */
function initWindow_report_export(){
    // 弹出弹出框
   Ext.create('Ext.window.Window', {
       title: '导出报表', // 窗口标题
       width: document.body.clientWidth * 0.4, // 窗口宽度
       height: document.body.clientHeight * 0.8, // 窗口高度
       layout: 'fit',
       maximizable: true,
       buttonAlign: 'right', // 按钮显示的位置
       modal: true, // 模式窗口，弹出窗口后屏蔽掉其他组件
       closeAction: 'destroy',// hide:单击关闭图标后隐藏，可以调用show()显示。如果是destroy，则会将window销毁。
       items: initWindow_report_export_content(),
       buttons: [{
    	   xtype:'textfield',
    	   fieldLabel: '<span class="required">✶</span>导出文件名称',
    	   name: 'EXPORT_FILE_NAME',
    	   labelAlign: "left",
    	   labelWidth: 100,
    	   width:'68%',
    	   value:'报表设计',
    	   allowBlank: false// 允许为空
       },{
    	   xtype: 'button',
    	   text: '导出',
		   handler: function (self) {
			   var fileName = Ext.ComponentQuery.query('textfield[name="EXPORT_FILE_NAME"]')[0].getValue();
			   var exportTreePanel = Ext.ComponentQuery.query('treepanel#exportReportTree')[0];
			   var records = exportTreePanel.getView().getChecked();
			   var qids = [];
			   Ext.Array.each(records, function (rec) {
				   if(rec.get('leaf')){
					   qids.push(rec.get('id'));
				   }
			   });
			   if(qids.length == 0){
				   return;
			   }
			   /*
				 * DSYGrid.exportExcelClick('reportGrid', { exportExcel: true,
				 * url: 'expQueryReport.action', param: { qids:qids,
				 * fileName:fileName } });
				 */
			   if (!$('form#download') || $('form#download').length <= 0) {
		            $('<form id="download"></form> ').appendTo(document.body);
		        }
		        // var frm = document.createElement('form');chrome有效,IE无效
		        Ext.Ajax.request({
		            url: '/sys-report/expQueryReport',
		            isUpload: true,
		            form: 'download',
		            params: {
						   qids:qids,
						   fileName:fileName
					   }
		        });
		   }
       },{
    	   xtype: 'button',
    	   text: '关闭',
    	   handler: function (self) {
    		   self.up('window').close();
    	   }
       }]
   }).show();
}	  

/**
 * 报表导出
 * 
 * @returns
 */
function initWindow_report_export_content(){
	var exportReportStroe = new Ext.data.TreeStore({
	    model: 'reportTreeModel',
	    proxy: {
	        type: 'ajax',
	        actionMethods:'POST',
	        url: '/sys-report/getExportReportTree',
	        reader: {
	            type: 'json'
	        }
	    },
	    autoLoad: true
	});
    var form = Ext.create('Ext.panel.Panel', {
    	width: '100%',
        height: '100%',
        scrollable:true,
        border:false,
        layout: 'fit',
        items: [{
        	xtype:'treepanel',
        	itemId: 'exportReportTree',
        	store: exportReportStroe,
        	rootVisible: false,
        	listeners: {
        		checkchange:function(node,checked){
        			if(!node.loaded){// 子节点是否加载 
        				node.expand();  
        			}
        			if(node.parentNode && node.parentNode.id!='root'){  
        				selectParentNodes(node,checked);// 是否选定父节点  
        			}
        			selectChildNodes(node,checked); 
        		}
        	}
        }]
    });
    return form;
}


/**
 * 递归获取父
 * 
 * @param node
 * @param checked
 * @returns
 */
function selectParentNodes(node,checked){
	var partial = true;
	if(node.parentNode && node.parentNode.id!='root'){
		var parent = node.parentNode;
		parent.eachChild(function (parentChild) {
			 if (parentChild.get("checked") != checked) {
				 parent.set("checked", false);
                 partial = false;
                 return false;
             }
        });
		if (partial) {
            parent.set("checked", checked);
        }
		selectParentNodes(node.parentNode,checked);
	}
};

/**
 * 递归获取子
 * 
 * @param node
 * @param checked
 * @returns
 */
function selectChildNodes(node,checked){
	node.eachChild(function(childNode){  
		childNode.set('checked', checked);
		if(!childNode.leaf){  
			if(!childNode.loaded){  
				childNode.expand();  
			}  
			selectChildNodes(childNode,checked);  
		}  
	});
};

/**
 * 打印配置
 * 
 * @param config
 * @returns
 */
function initWindow_report_print_config(config){
    // 弹出弹出框
   Ext.create('Ext.window.Window', {
       title: config.title, // 窗口标题
       width: document.body.clientWidth * 0.65, // 窗口宽度
       height: document.body.clientHeight * 0.65, // 窗口高度
       layout: 'fit',
       maximizable: true,
       itemId: 'initWindow_report_print_config', // 窗口标识
       buttonAlign: 'right', // 按钮显示的位置
       modal: true, // 模式窗口，弹出窗口后屏蔽掉其他组件
       closeAction: 'destroy',// hide:单击关闭图标后隐藏，可以调用show()显示。如果是destroy，则会将window销毁。
       items: initWindow_report_print_contentForm(config),
       buttons: [{
    	   xtype: 'button',
    	   text: '保存',
    	   handler: function (self) {
    		   var form = self.up('window').down('form');
    		   if (form.isValid()) {
    			   var formData = form.getForm().getFieldValues();
    			   formData = $.extend({}, formData, form.getValues());
    			   formData.Q_ID = config.data.Q_ID;
    			   $.post('/sys-report/saveReportPrintConfig', {
    				   detailForm: Ext.util.JSON.encode([formData])
    			   }, function (data) {
    				   if (data.success) {
    					   Ext.toast({
    						   html: "保存成功！",
    						   closable: false,
    						   align: 't',
    						   slideInDuration: 400,
    						   minWidth: 400
    					   });
    					   self.up('window').close();
    				   } else {
    					   Ext.MessageBox.alert('提示', '保存失败!' + data.message);
    				   }
    			   }, 'JSON');
    		   }
    	   }
       },{
    	   xtype: 'button',
    	   text: '关闭',
    	   handler: function (self) {
    		   self.up('window').close();
    	   }
       }]
   }).show();
}


/**
 * 打印配置
 * 
 * @param config
 * @returns
 */
function initWindow_report_print_contentForm(config) {
    var form = Ext.create('Ext.form.Panel', {
        width: '100%',
        height: '100%',
        itemId: 'initWindow_report_print_contentForm',
        layout: 'column',
        scrollable:true,
        defaultType: 'fieldset',
        defaults: {
            margin: '4 4 4 10',
            columnWidth: .99
        },
        items: [{
        	title: '页眉',
        	layout: 'column',
        	defaultType: 'textareafield',
        	defaults: {
        		margin: '5 0 5 5',
        		columnWidth: 0.33,
        		height:document.body.clientHeight * 0.2,
        		labelWidth: 35// 控件默认标签宽度
        	},
        	items:[{
        		fieldLabel: '左(L)',
        		name:'HEADER_LEFT'
        	},{
        		fieldLabel: '中(C)',
        		name:'HEADER_CENTER'
        	},{
        		fieldLabel: '右(R)',
        		name:'HEADER_RIGHT'
        	}]
        },{
        	title: '页脚',
        	layout: 'column',
        	defaultType: 'textareafield',
        	defaults: {
        		margin: '5 0 5 5',
        		columnWidth: 0.33,
        		height:document.body.clientHeight * 0.2,
        		labelWidth: 35// 控件默认标签宽度
        	},
        	items:[{
        		fieldLabel: '左(L)',
        		name:'FOOTER_LEFT'
        	},{
        		fieldLabel: '中(C)',
        		name:'FOOTER_CENTER'
        	},{
        		fieldLabel: '右(R)',
        		name:'FOOTER_RIGHT'
        	}]
        }]
    });
    form.getForm().setValues(config.data);
    return form;
}


/**
 * 刷新字段
 * 
 * @returns
 */
function refreshFieldTree(){
	var fieldTree = Ext.ComponentQuery.query('treepanel#fieldTree')[0];
    var fieldStore = fieldTree.getStore();
    fieldStore.getProxy().extraParams = {
    	q_id:q_id
    };
    fieldStore.load();
}


function dragDisable(){
	$("#dragDiv").css('display','none');
}

function dragEnable(){
	if(dropValue){
		$("#dragDiv").css('display','block');
	}
}
